package sivak.net.proc.dyn.single_lib_1;

import sivak.net.proc.dyn.single_lib_1.Node;

/**
 * Created with IntelliJ IDEA.
 * User: root
 * Date: 1/23/13
 * Time: 12:22 PM
 * To change this template use File | Settings | File Templates.
 */
public class SingleLLUtils_1 {

    public static int length(Node tail) {
        int length = 0;
        while (tail != null) {
            length++;
            tail = tail.next;
        }
        return length;
    }

    public static int max(Node tail) {
        if (tail == null) {
            throw new IllegalArgumentException();
        }
        int max = tail.value;
        while (tail.next != null) {
            max = Math.max(max, tail.next.value);
            tail = tail.next;
        }
        return max;
    }

    public static int sum(Node tail) {
        int sum = 0;
        while (tail != null) {
            sum += tail.value;
            tail = tail.next;
        }
        return sum;
    }

}
